<?php 
$output = 'var tinyMCEImageList = new Array(';
$delimiter = "\n";

//$fileDir ="../../upload/images"; // Use your correct (relative!) path here
//$fileDir ="../../../../uploads/images/2013-Feb-13"; // Use your correct (relative!) path here


$fileDir = $_SERVER['DOCUMENT_ROOT'] . "/uploads/images/2013-Feb-13"; // Use your correct (relative!) path here

$url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'? 'https://': 'http://';
$url .= $_SERVER['SERVER_NAME'].'/uploads/images/2013-Feb-13';


$abspath = preg_replace('~^/?(.*)/[^/]+$~', '/$1', $_SERVER['SCRIPT_NAME']);// Since TinyMCE3.x you need absolute image paths

if(is_dir($fileDir))
{   if($direc = opendir($fileDir)){ }else{ }//end if else
    while($file = readdir($direc)) 
	{   //if(!preg_match('~^.~', $file)) 
		if(preg_match('~^.~', $file))// no hidden files / directories here...
		{	if(is_file("{$fileDir}/{$file}") && getimagesize("{$fileDir}/{$file}") != FALSE) 
			{	$output .= $delimiter.'["'.utf8_encode($file).'", "'.utf8_encode($url . "/{$file}").'"],';
            }//end if
        }else{ echo "tt";	}//end if
    }//end while loop
    $output = substr($output, 0, -1); // remove last comma from array item list (breaks some browsers)
    $output .= $delimiter;
    closedir($direc);
}//end if
$output .= ');';

header('Content-type: text/javascript'); //browser will now recognize the file as a valid JS file
header('pragma: no-cache'); // prevent browser from caching
header('expires: 0'); // i.e. contents have already expired
echo $output;
?>